1 module core_3;
2 import defs;
3 import util;
4 
5 enum FilesLocation = "man3/";
6 enum FileGlob = "gl*.xml";
7 enum PrependXMLFileLocation = "man3/";
8 
9 OGLFunctionFamily[] readInFunctionFamilies() {
10 	import std.file : dirEntries, SpanMode;
11 	OGLFunctionFamily[] ret;
12 
13 	foreach(string entry; dirEntries(FilesLocation, FileGlob, SpanMode.shallow)) {
14 		//if (entry == FilesLocation ~ "glVertexAttrib.xml")
15 			ret ~= OGLFunctionFamily(entry, entry[FilesLocation.length .. $-4]);
16 	}
17 
18 	foreach(ref family; ret) {
19 		family.functions = family.readInFunctions;
20 
21 		import std.stdio;
22 		//writeln(family);
23 	}
24 
25 	return ret;
26 }
27 
28 OGLFunction[] readInFunctions(ref OGLFunctionFamily family) {
29 	import std.file : readText;
30 	import std.experimental.xml;
31 	import core_4_5 : evaluateDocs;
32 
33 	string raw_input = readText(family.fromFilename);
34 	OGLFunction[] ret;
35 	
36 	if (raw_input.length < 72) {
37 		return null;
38 	} else
39 		raw_input = raw_input[71 .. $];
40 	
41 	auto domBuilder = raw_input
42 		.lexer
43 			.parser
44 			.cursor((CursorError err){})
45 			.domBuilder;
46 	domBuilder.setSource(raw_input);
47 	domBuilder.buildRecursive;
48 	auto dom = domBuilder.getDocument;
49 	
50 	//
51 
52 	auto refsect1 = dom.getElementsByTagName("refsect1");
53 	foreach(node; refsect1) {
54 		if (node.attributes.getNamedItem("id") is null)
55 			continue;
56 
57 		size_t i;
58 		switch(node.attributes.getNamedItem("id").nodeValue) {
59 			case "description":
60 				i = 0;
61 				foreach(child; node.childNodes) {
62 					i++;
63 					if (i == 1)
64 						continue;
65 					family.docs_description.evaluateDocs(child);
66 				}
67 				break;
68 		
69 			case "notes":
70 				i = 0;
71 				foreach(child; node.childNodes) {
72 					i++;
73 					if (i == 1)
74 						continue;
75 					family.docs_notes.evaluateDocs(child);
76 				}
77 				break;
78 		
79 			case "seealso":
80 				i = 0;
81 				foreach(child; node.childNodes) {
82 					i++;
83 					if (i == 1)
84 						continue;
85 					family.docs_seealso.evaluateDocs(child);
86 				}
87 				break;
88 		
89 			case "Copyright":
90 				i = 0;
91 				foreach(child; node.childNodes) {
92 					i++;
93 					if (i == 1)
94 						continue;
95 					family.docs_copyright.evaluateDocs(child);
96 				}
97 				break;
98 				
99 			case "errors":
100 				i = 0;
101 				foreach(child; node.childNodes) {
102 					i++;
103 					if (i == 1)
104 						continue;
105 					family.docs_errors.evaluateDocs(child);
106 				}
107 				break;
108 				
109 			default:
110 				break;
111 		}
112 	}
113 
114 	//
115 
116 	auto funcSynopsises = dom.getElementsByTagName("funcsynopsis");
117 	size_t funcprototypesCount;
118 	foreach(funcSynopsis; funcSynopsises) {
119 		funcprototypesCount += funcSynopsis.childNodes.length;
120 	}
121 	ret.length = funcprototypesCount;
122 
123 	size_t i;
124 	foreach(funcSynopsisI; 0 .. funcSynopsises.length) {
125 	F2: foreach(funcprototype; funcSynopsises[funcSynopsisI].childNodes) {
126 			switch(funcprototype.nodeName) {
127 				case "funcprototype":
128 					break;
129 				default:
130 					ret.length--;
131 					continue F2;
132 			}
133 
134 			ret[i].returnType = funcprototype.firstChild.firstChild.nodeValue.fixTypePointer;
135 			ret[i].name = funcprototype.firstChild.lastChild.firstChild.nodeValue;
136 
137 			ret[i].argNames.length = funcprototype.childNodes.length;
138 			ret[i].argTypes.length = ret[i].argNames.length;
139 			
140 			size_t j;
141 			foreach(paramdef; funcprototype.childNodes) {
142 				switch(paramdef.nodeName) {
143 					case "paramdef":
144 						break;
145 					default:
146 						ret[i].argNames.length--;
147 						ret[i].argTypes.length--;
148 						continue;
149 				}
150 				
151 				if (paramdef.firstChild.nodeValue.length > 0) {
152 					ret[i].argTypes[j] = paramdef.firstChild.nodeValue.fixTypePointer;
153 					
154 					if (ret[i].argTypes[j].length > 0 && ret[i].argTypes[j][$-1] == ' ')
155 						ret[i].argTypes[j].length--;
156 					
157 					if (paramdef.childNodes.length == 2)
158 						ret[i].argNames[j] = paramdef.lastChild.firstChild.nodeValue;
159 				} else
160 					ret[i].argTypes[j] = paramdef.firstChild.firstChild.nodeValue.fixTypePointer;
161 				
162 				j++;
163 			}
164 			
165 			i++;
166 		}
167 	}
168 
169 	//
170 
171 
172 
173 	//
174 
175 	return ret;
176 }